/**
 * api 接口
 * @author: leon
 * @create: 2017-10-18 17:25
 */


import axios from 'axios';

export const baseURL = {
    test: 'dev.com',
    development: 'dev.com',
    production: 'product.com'
}[process.env.NODE_ENV];

const axiosInstance = axios.create({
    baseURL,
    headers: {
        'Content-Type': 'application/json; charset=UTF-8'
    },
    withCredentials: true,
    timeout: 5000
});

axiosInstance.interceptors.request.use(config => {
    if (config.method === 'post') {
        config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
    }

    return config;
}, error => {
    return Promise.reject(error);
});


export default axiosInstance;
